﻿<phone:PhoneApplicationPage 
    x:Class="Coevery.PhoneApp.LeadDetail"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:myConverter="clr-namespace:Coevery.PhoneApp.Convert"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False" BackKeyPress="PhoneApplicationPage_BackKeyPress">

    <phone:PhoneApplicationPage.Resources>
        <myConverter:ColorConverter x:Name="ColorConverter"></myConverter:ColorConverter>
        <myConverter:MetadataConverter x:Name="MetadataConverter"></myConverter:MetadataConverter>
        <DataTemplate x:Name="LeadDetailTemplate">
            <StackPanel Width="450" Orientation="Vertical">
                <StackPanel  Margin="0 5 0 0" Orientation="Horizontal">
                    <Image Source="Images/customer.png"></Image>
                    <TextBlock Text="{Binding FullName}" Margin="5 0 0 0"  FontSize="26"   Foreground="Black"  TextWrapping="Wrap"></TextBlock>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0 5 0 0">
                    <TextBlock Text="{Binding Subject}" Foreground="Black"  HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0 10 0 0">
                    <StackPanel Orientation="Vertical" Width="225" >
                        <TextBlock  Text="Country" Foreground="#0597d2" Width="110" HorizontalAlignment="Left"></TextBlock>
                        <TextBlock   Foreground="Black" HorizontalAlignment="Left">
                         <TextBlock.Text>
                            <Binding Path="Country" StringFormat="{} ({0})"></Binding>
                        </TextBlock.Text>
                        </TextBlock>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Width="225" >
                        <TextBlock  Text="Source" Foreground="#0597d2" Width="110"  HorizontalAlignment="Left"></TextBlock>
                        <TextBlock  Text="{Binding LeadSourceCode, Converter={StaticResource MetadataConverter}, ConverterParameter=lead_leadsourcecode}"  Foreground="Black"  HorizontalAlignment="Left"></TextBlock>
                    </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0 10 0 0">
                    <StackPanel Orientation="Vertical" Width="225">
                        <TextBlock  Text="Technology"  Foreground="#0597d2" Width="110"  HorizontalAlignment="Left"></TextBlock>
                        <TextBlock  Text="{Binding Technology}"   Foreground="Black"  HorizontalAlignment="Left"></TextBlock>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Width="225">
                        <TextBlock  Text="Status"  Foreground="#0597d2" Width="110"   HorizontalAlignment="Left"></TextBlock>
                        <TextBlock  Text="{Binding StatusCode,Converter={StaticResource MetadataConverter}, ConverterParameter=lead_statuscode}"  Foreground="Black"   HorizontalAlignment="Left"></TextBlock>
                    </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0 10 0 0">
                    <TextBlock  Text="Update Date"  Foreground="#0597d2" Width="110"   HorizontalAlignment="Left"></TextBlock>
                    <TextBlock  Text="{Binding ModifiedOn}"  Foreground="Black"   HorizontalAlignment="Left"></TextBlock>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0 20 0 0">
                    <Image Source="Images/phone_24.png"  Hold="MobilePhone_Hold"></Image>
                    <TextBlock  Text="{Binding MobilePhone}" Margin="10 0 0 0"  Hold="MobilePhone_Hold" Foreground="Blue" VerticalAlignment="Center"  HorizontalAlignment="Left"></TextBlock>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                    <Image Source="Images/email_24.png" Hold="Email_Hold"></Image>
                    <TextBlock  Text="{Binding EmailAddress}" Margin="10 0 0 0" Hold="Email_Hold" TextDecorations="Underline" Foreground="Blue" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                    <Image Source="Images/website_24.png" Hold="WebSiteUrl_Hold"></Image>
                    <TextBlock  Text="{Binding WebSiteUrl}" Margin="10 0 0 0" Hold="WebSiteUrl_Hold" TextDecorations="Underline"   Foreground="Blue" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
                </StackPanel>
                <StackPanel Margin="0 20 0 0">
                    <TextBlock  Text="Description"  Foreground="#0597d2" Width="110"   HorizontalAlignment="Left"></TextBlock>
                    <TextBlock Text="{Binding Description}"   Margin="0 5" TextWrapping="Wrap" Foreground="Black"  VerticalAlignment="Top"></TextBlock>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Name="LeadCommentsTemplate" >
            <Border>
                <StackPanel Width="450" Margin="5,5,5,5" VerticalAlignment="Top">
                    <StackPanel Orientation="Horizontal" >
                        <StackPanel Width="225" Orientation="Horizontal">
                        <Image Source="Images/customer.png" Margin="5 0 0 0"></Image>
                        <TextBlock DataContext="{Binding ModifiedBy}" Margin="5 0 0 0" Text="{Binding FullName}"  TextWrapping="Wrap" Foreground="Black" ></TextBlock>
                        </StackPanel>
                        <StackPanel Width="225">
                            <TextBlock Text="{Binding ModifiedOn}"  TextAlignment="Right"  Foreground="#aeb3b6" ></TextBlock>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel  Margin="0 5 0 0">
                        <TextBlock Text="{Binding Subject}" Margin="27 0 0 0"  FontSize="28"  TextWrapping="Wrap" Foreground="Black" ></TextBlock>
                    </StackPanel>
                    <StackPanel Margin="0 5 0 0">
                        <TextBlock Text="{Binding NoteText}" Margin="27 0 0 0"  TextWrapping="Wrap" Foreground="Black"></TextBlock>
                    </StackPanel>
                    <toolkit:ContextMenuService.ContextMenu>
                        <toolkit:ContextMenu>
                            <toolkit:MenuItem Header="Edit" Click="EditLeadComment_Click"/>
                            <toolkit:MenuItem Header="Delete" Click="DeleteLeadComment_Click"/>
                        </toolkit:ContextMenu>
                    </toolkit:ContextMenuService.ContextMenu>
                </StackPanel>
            </Border>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <controls:Pivot x:Name="ctlPanorama" Foreground="#0597d2">
            <controls:PivotItem Header="Detail" x:Name="PanDetail">
                <ListBox x:Name="leadDetailListBox" Margin="0,0,-12,0" ItemsSource="{Binding Leads}" ItemTemplate="{StaticResource LeadDetailTemplate}">
                </ListBox>
            </controls:PivotItem>

            <controls:PivotItem Header="Comments" x:Name="PanComments">
                <ListBox x:Name="leadCommentsListBox" Margin="0,0,-12,0" ItemsSource="{Binding Notes}" ItemTemplate="{StaticResource LeadCommentsTemplate}">
                </ListBox>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" BackgroundColor="#0066cc" Opacity="10">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.feature.home.rest.png" Text="Home"  Click="Home_Click"></shell:ApplicationBarIconButton>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.add.rest.png" Text="Add Comment"  Click="AddComments_Click"></shell:ApplicationBarIconButton>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.refresh.rest.png" Text="Refresh" Click="Refresh_Click" ></shell:ApplicationBarIconButton>

            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="Convert to assigned" Click="ApplicationBarMenuItem_Click"/>
                <shell:ApplicationBarMenuItem Text="Convert to in process" Click="ApplicationBarMenuItem_Click"/>
                <shell:ApplicationBarMenuItem Text="Convert to converted" IsEnabled="False"/>
                <shell:ApplicationBarMenuItem Text="Convert to recycled" Click="ApplicationBarMenuItem_Click"/>
                <shell:ApplicationBarMenuItem Text="Convert to dead" Click="ApplicationBarMenuItem_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>